package com.example.mobile2021606127cxz0323homework;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    public void initView() {
        TextView edtTxt_user = findViewById(R.id.edtTxt_main_user);
        EditText edtTxt_old = findViewById(R.id.edtTxt_main_old);
        EditText edtTxt_new = findViewById(R.id.edtTxt_main_new);
        EditText edtTxt_newagain = findViewById(R.id.edtTxt_main_newagain);
        Button btn_xiugai = findViewById(R.id.btn_main_xiugai);
        btn_xiugai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String user = edtTxt_user.getText().toString().trim();
                String oldpsw = edtTxt_old.getText().toString().trim();
                String newpsw = edtTxt_new.getText().toString().trim();
                String newagain = edtTxt_newagain.getText().toString().trim();

//    if (user.length()==0 && oldpsw.length()==0 && newpsw.length()==0 && newagain.length()==0){
//        Toast.makeText(MainActivity.this,"用户名和密码不能为空",Toast.LENGTH_SHORT).show();
//    }
//
//            if (user.length()==0 && oldpsw.length()!=0 || newpsw.length()!=0 || newagain.length()!=0){
//                Toast.makeText(MainActivity.this,"用户名不能为空",Toast.LENGTH_SHORT).show();
//            }
//
//
//            if (user.length()!=0 && oldpsw.length()==0 || newpsw.length()==0 || newagain.length()==0){
//                Toast.makeText(MainActivity.this,"密码不能为空",Toast.LENGTH_SHORT).show();
//            }
//
//
//            if (user.length()!=0 && oldpsw.length()!=0 && newpsw.length()!=0 && newagain.length()!=0){
//                if (user.length()<6){
//                    Toast.makeText(MainActivity.this,"用户名长度应在6~10个字之间",Toast.LENGTH_SHORT).show();
//                }else if (user.length()>=10){
//                    Toast.makeText(MainActivity.this,"用户名长度应在6~10个字之间",Toast.LENGTH_SHORT).show();
//                }
//                if (edtTxt_old.getText().toString().trim().equals("abc123")){
//                    Toast.makeText(MainActivity.this,"",Toast.LENGTH_SHORT).show();
//                }else {
//                    Toast.makeText(MainActivity.this,"旧密码不正确",Toast.LENGTH_SHORT).show();
//                }
//                if (edtTxt_new.getText().toString().trim().equals(edtTxt_newagain.getText().toString().trim())){
//                    Toast.makeText(MainActivity.this,"修改成功",Toast.LENGTH_SHORT).show();
//                }else {
//                    Toast.makeText(MainActivity.this,"两次输入的新密码不一致，请重新检查",Toast.LENGTH_SHORT).show();
//                }
//                  }


                if (user.length() == 0 | oldpsw.length() == 0 | newpsw.length() == 0 | newagain.length() == 0) {
                    Toast.makeText(MainActivity.this, "用户名和密码不能为空", Toast.LENGTH_SHORT).show();
                } else if (user.length() < 6) {
                    Toast.makeText(MainActivity.this, "用户名长度应在6~10个字之间", Toast.LENGTH_SHORT).show();
                } else if (user.length() >= 10) {
                    Toast.makeText(MainActivity.this, "用户名长度应在6~10个字之间", Toast.LENGTH_SHORT).show();
                } else if (!edtTxt_old.getText().toString().trim().equals("abc123")) {
                    Toast.makeText(MainActivity.this, "旧密码不正确，请重新输入", Toast.LENGTH_SHORT).show();
                } else if (edtTxt_new.getText().toString().trim().equals(edtTxt_newagain.getText().toString().trim())) {
                    Toast.makeText(MainActivity.this, "修改成功", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this, "两次输入的新密码不一致，请重新检查", Toast.LENGTH_SHORT).show();
                }
                Log.i("information", "获取到的信息为:" + "   " + "用户名：" + user + "    " + "旧密码：" + oldpsw + "    " + "新密码：" + newpsw + "    " + "确认密码：" + newagain);
            }

        });
    }

}




